#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN DATA ABSTRACTION LAYER version 1

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Using directives
using System;
#endregion

namespace Thn.Data
{
    /// <summary>
    /// Attribute for object caching
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class CachedAttribute : Attribute
    {
        #region Mode
        private CacheMode mMode = CacheMode.All;
        /// <summary>
        /// Gets/Sets mode of caching. Default is All
        /// </summary>
        public CacheMode Mode
        {
            get { return mMode; }
            set { mMode = value; }
        }
        #endregion

        #region Time Out
        private int mTimeOut;
        /// <summary>
        /// Gets/Sets the duration (in seconds) this object is cached.
        /// <para>Default is zero (never dies automatically if cached)</para>
        /// <para>When this number is a positive value, the object will be automatically purged from memory when time-out expires</para>
        /// </summary>
        public int TimeOut
        {
            get { return mTimeOut; }
            set 
            {
                if (value >= 0) mTimeOut = value;
            }
        }
        #endregion
	
        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public CachedAttribute()
        { }

        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="mode">mode of caching</param>
        public CachedAttribute(CacheMode mode)
        {
            mMode = mode;
        }

        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="timeOut">the duration (in seconds) this object is cached.</param>
        public CachedAttribute(int timeOut)
        {
            mTimeOut = timeOut;
        }

        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="mode">mode of caching</param>
        /// <param name="timeOut">the duration (in seconds) this object is cached.</param>
        public CachedAttribute(CacheMode mode, int timeOut)
        {
            mMode = mode;
            mTimeOut = timeOut;
        }
        #endregion
    }
}
